﻿/****************************************************
    文件：#SCRIPTNAME#.cs
	作者：GHC
    邮箱: 1191775201@qq.com
    日期：#CreateTime#
	功能：游戏管理
*****************************************************/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GameManager : MonoBehaviour
{
    public List<Player> Player = new List<Player>();
    public GameObject AIPanel;

    private void Awake()
    {
        int player1 = PlayerPrefs.GetInt("Player1");
        int player2= PlayerPrefs.GetInt("Player2");


        for (int i = 0; i < Player.Count; i++)
        {
            if (player1 == i)
            {
                Player[i].chessColor = ChessType.Black;
            }else if(player2 == i)
            {
                Player[i].chessColor = ChessType.White;
            }
            else
            {
                Player[i].chessColor = ChessType.Watch;
            }
        }
    }

    public void SetPlayer1(int i)
    {
        PlayerPrefs.SetInt("Player1", i);
    }

    public void SetPlayer2(int i)
    {
        PlayerPrefs.SetInt("Player2", i);
    }

    public void PlayGame()
    {
        SceneManager.LoadScene(1);
    }

    public void PlayNetWork()
    {
        SceneManager.LoadScene(3);
    }

    public void ChangeChessColor()
    {
        for (int i = 0; i < Player.Count; i++)
        {
            if (Player[i].chessColor == ChessType.Black)
            {
                SetPlayer2(i);
            }
            else if ((Player[i].chessColor == ChessType.White))
            {
                SetPlayer1(i);
            }
            else
            {
                Player[i].chessColor = ChessType.Watch;
            }
        }
        SceneManager.LoadScene(1);
    }

    public void DoubleMode()
    {
        PlayerPrefs.SetInt("Double", 10);
    }

    public void OnReturnBtn()
    {
        PlayerPrefs.SetInt("Double", 1);
        SceneManager.LoadScene(0);
    }

    public void OnAIClick()
    {
        AIPanel.SetActive(true);
    }
}
